package org.shj.pattern.memento

import scala.collection.mutable.HashMap

class Memento(val health: Int, val magic: Int) {
  
}

class Originator(var curHealth: Int, var curMagic: Int){
  
  
  def saveState(): Memento = {
    new Memento(curHealth, curMagic)
  }
  
  def recover(memento: Memento) {
    curHealth = memento.health
    curMagic = memento.magic
  }
  
  override def toString(): String = {
    "curHealth: " + curHealth + "; curMagic: " + curMagic
  }
}

class CareTaker{
  val stateMap = new HashMap[String, Memento]()
  
  def add(jingdu: String, memento: Memento){
    stateMap += jingdu -> memento
  }
  
  def get(jingdu: String): Memento= {
    stateMap.getOrElse(jingdu, new Memento(0,0))    
  }
}